home *** CD-ROM | disk | FTP | other *** search
/ Programming Sound Cards / Programming Sound Cards.iso / sound_45 / misc.h < prev    next >
C/C++ Source or Header  |  1995-01-01  |  6KB  |  217 lines

  1. /* BEGIN SOX COPYRIGHT ************************************************ */
  2. /*
  3.  * July 5, 1991
  4.  * Copyright 1991 Lance Norskog And Sundry Contributors
  5.  * This source code is freely redistributable and may be used for
  6.  * any purpose.  This copyright notice must be maintained. 
  7.  * Lance Norskog And Sundry Contributors are not responsible for 
  8.  * the consequences of using this software.
  9.  */
  10. /* END   SOX COPYRIGHT ************************************************ */
  11.  
  12. /* copied from sox */
  13. /* modified by David Lai, Jan 6 1993, daver!fastfood!lai */
  14.  
  15. /* BEGIN DAVID LAI COPYRIGHT ********************************************* */
  16. /*
  17. (C) Copyright David Lai 1993, 1994.  All rights reserved.
  18.  
  19. The source code is copyright by David Lai, however it is freely
  20. distributable and released for unrestricted use.  Users may copy or modify 
  21. this source code without charge, provided all copyright
  22. notices remain intact in all the source code.  Portions of the source code
  23. copyright by their respective copyright holders and are covered
  24. under different agreements, however the source code used has
  25. specifically been marked distributable royalty-free.
  26.  
  27. You can do whatever you want with it, even charge money for it, if
  28. you find a sucker willing to pay for it.  This is not shareware, the program
  29. is not crippled in any way, do not send money.  You can e-mail comments
  30. to the electronic mail address below, or fax to the fax number below.
  31.  
  32. If you add a feature thats useful, or do a new port, you can send
  33. the context diffs to the e-mail address below.  I may include it in
  34. subsequent releases.  Your code must specifically be marked
  35. freely distributable, I will not include code marked otherwise.
  36.  
  37. THE SOURCE CODE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING
  38. THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  39. PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  40.  
  41. The source code is provided with no support and without any obligation on
  42. the part of David Lai to assist in its use, correction,
  43. modification or enhancement.
  44.  
  45. DAVID LAI SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  46. INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS SOFTWARE
  47. OR ANY PART THEREOF.
  48.  
  49. In no event will David Lai be liable for any lost revenue
  50. or profits or other special, indirect and consequential damages, even if
  51. David Lai has been advised of the possibility of such damages.
  52.  
  53. David Lai
  54. 1370 McKendrie St
  55. San Jose, CA 95126
  56. fax: 408-241-4615
  57.  
  58. lai%fastfood@daver.bungi.com
  59.  
  60. */
  61. /* END   DAVID LAI COPYRIGHT ********************************************* */
  62.  
  63. /* sometimes microsoft C only defines _DOS */
  64. #ifdef _DOS
  65. #ifndef __MSDOS__
  66. #define __MSDOS__
  67. #endif
  68. #endif
  69.  
  70. #ifdef VAXC
  71. #define IMPORT  globalref
  72. #define EXPORT  globaldef
  73. /*
  74.  * use the VAX C optimized functions 
  75.  */ 
  76. #define calloc  VAXC$CALLOC_OPT
  77. #define cfree   VAXC$CFREE_OPT
  78. #define free    VAXC$FREE_OPT
  79. #define malloc  VAXC$MALLOC_OPT
  80. #define realloc VAXC$REALLOC_OPT
  81. #else
  82. #define IMPORT  extern
  83. #define EXPORT 
  84. #endif
  85.  
  86. #ifdef __STDC__
  87. #define PROTO(x) x
  88. #else
  89. /* Some non-ansi compilers (eg. sun SunOs version 4) */
  90. #define signed
  91. #define const
  92. #define volatile
  93. #define PROTO(x) ()
  94. #define NO_CONSTANT_SUFFIX
  95. #endif
  96.  
  97. #ifdef sun
  98. /* SunOs version 4 doesnt define SEEK_SET */
  99. #define SEEK_SET 0
  100. #endif
  101.  
  102. #include <stdio.h>
  103. #include <stdlib.h>
  104. #include <string.h>
  105. #include <ctype.h>
  106. #include <sys/types.h>
  107. #include <sys/stat.h>
  108. #include <assert.h>
  109.  
  110. #ifdef AMIGA
  111. #include "amiga.h"
  112. #endif /* AMIGA */
  113.  
  114. #ifdef    __STDC__
  115. #define    P1(x) x
  116. #define    P2(x,y) x, y
  117. #define    P3(x,y,z) x, y, z
  118. #define    P4(x,y,z,w) x, y, z, w
  119. #else
  120. #define P1(x)
  121. #define P2(x,y)
  122. #define P3(x,y,z)
  123. #define P4(x,y,z,w)
  124. #endif
  125.  
  126. #ifdef __MSDOS__
  127.     /* the only compiler I know of where int is 16 bits */
  128. #define int16    int
  129. #define int32    long
  130. #define uint16    unsigned int
  131. #define uint32    unsigned long
  132. #define FMT_I32 "%ld"
  133. #define FMT_U32 "%lu"
  134. #else
  135. #define int16    short
  136. #define int32    int
  137. #define uint16    unsigned short
  138. #define uint32    unsigned int
  139. #define FMT_I32 "%d"
  140. #define FMT_U32 "%u"
  141. #endif
  142.  
  143. #if defined(__MSDOS__) || defined(VAXC)
  144. #define LE        /* little endian */
  145. #else
  146. #define BE        /* big endian */
  147. #endif
  148.  
  149. /* Utilities to read and write shorts and longs little-endian and big-endian */
  150. uint16 rlshort(P1(FILE * ft));            /* short little-end */
  151. uint16 rbshort(P1(FILE * ft));            /* short big-end    */
  152. void wlshort(P2(FILE * ft, uint16 us));    /* short little-end */
  153. void wbshort(P2(FILE * ft, uint16 us));    /* short big-end    */
  154. uint32  rllong(P1(FILE * ft));            /* long little-end  */
  155. uint32  rblong(P1(FILE * ft));            /* long big-end     */
  156. void  wllong(P2(FILE * ft, uint32 ul));    /* long little-end  */
  157. void  wblong(P2(FILE * ft, uint32 ul));    /* long big-end     */
  158. void    wezstr( P2(FILE * ft, char *str));
  159.     /* write null term string + pad to even number of bytes */
  160.  
  161. #if    defined(unix) || defined(AMIGA) || defined (__OS2__) || defined(OS9)
  162. #define READBINARY    "r"
  163. #define WRITEBINARY    "w"
  164. #endif
  165. #ifdef    VMS
  166. #define READBINARY      "r", "mbf=16", "ctx=stm" 
  167. #define WRITEBINARY     "w", "ctx=stm"
  168. #endif
  169. #ifdef    __MSDOS__ 
  170. #define READBINARY    "rb"
  171. #define WRITEBINARY    "wb"
  172. #endif
  173.  
  174. /* Error code reporting */
  175. #ifdef    QNX
  176. #include <errno.h>
  177. #endif
  178.  
  179. #if defined(unix) || defined(__OS2__)
  180. #include <errno.h>
  181. extern errno;
  182. #if defined(i386) || !defined(__STDC__)
  183. /* usually be a const in stdlib.h ?? */
  184. /* this is turning out to be a headache */
  185. extern char *sys_errlist[];
  186. #define strerror(errno)    sys_errlist[errno]
  187. #endif
  188. #endif
  189.  
  190. #ifdef    __OS2__
  191. #define REMOVE remove
  192. #else
  193. #define REMOVE unlink
  194. #endif
  195.  
  196. #define err_exit(str,arg) (fprintf(stderr, str, arg),fprintf(stderr,"\n"),exit(1))
  197. /* signed <> unsigned char conversions */
  198. #define s_to_u(c) ((c) ^ 128)
  199. #define u_to_s(uc) ((uc) ^ 128)
  200.  
  201. #ifndef __MSDOS__
  202. #define FWRITE fwrite
  203. #define FREAD fread
  204. #else
  205. extern uint32 FWRITE PROTO((const void * buffer, size_t size, uint32 count, FILE *stream));
  206. extern uint32 FREAD PROTO((const void * buffer, size_t size, uint32 count, FILE *stream));
  207. #endif
  208.  
  209. #if 0
  210. $Id: misc.h,v 1.1 1994/03/19 09:21:31 dlai Exp $
  211. $Log: misc.h,v $
  212.  * Revision 1.1  1994/03/19  09:21:31  dlai
  213.  * Initial revision
  214.  *
  215.  
  216. #endif
  217.